#region Using References

using System.IO;

#endregion

namespace Beaker.OpenCube.Specs.Builders
{
	public class TextStreamBuilder
		: Builder<Stream>
	{
		private readonly MemoryStream _memoryStream;
		private readonly StreamWriter _writer;

		public TextStreamBuilder()
		{
			_memoryStream = new MemoryStream();
			_writer = new StreamWriter( _memoryStream );
		}

		public TextStreamBuilder WithText( string text )
		{
			_writer.Write( text );
			return this;
		}

		protected override Stream OnBuild()
		{
			_writer.Flush();
			_memoryStream.Flush();
			_memoryStream.Position = 0;

			return _memoryStream;
		}
	}
}